package com.taiyi.renaissancemall.ui.mine.withdraw.bindaccount;

import android.content.Intent;

import com.taiyi.renaissancemall.Utils.ToastUtils;
import com.taiyi.renaissancemall.Utils.Utils;
import com.taiyi.renaissancemall.base.BasePresent;
import com.taiyi.renaissancemall.base.MyApp;
import com.taiyi.renaissancemall.bean.BaseResultBean;
import com.taiyi.renaissancemall.bean.EmptyBean;
import com.taiyi.renaissancemall.bean.VerifiedBean;
import com.taiyi.renaissancemall.net.BaseUrl;
import com.taiyi.renaissancemall.net.HttpUtils;
import com.taiyi.renaissancemall.net.callbck.JsonCallback;
import com.taiyi.renaissancemall.ui.login.LoginActivity;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Response;

public class BindAccountPresent extends BasePresent<BindAccountView> {

    public void getVerificationCode(String tel) {
        Map<String, String> map = new HashMap<>();
        map.put("uniquekey", MyApp.getDeviceUUid());
        map.put("tel", tel);
        HttpUtils.postRequest(BaseUrl.LOGIN_GET_VERIFICATION_CODE, this, map, new JsonCallback<BaseResultBean<EmptyBean>>() {
            @Override
            public BaseResultBean<EmptyBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<EmptyBean>> response) {
                super.onSuccess(response);
                ToastUtils.showLongToast(response.body().msg_cn);
                if (response.body().code == 0) {
                    view.getVerificationSuccess();
                } else if (response.body().code == -1) {
                    ToastUtils.showShortToast(response.body().msg_cn);
                    Utils.getSpUtils().remove("token");
                    Intent intent = new Intent(MyApp.getInstance(), LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApp.getInstance().startActivity(intent);
                } else {
                    view.getVerificationFailure();
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<EmptyBean>> response) {
                super.onError(response);
            }
        });
    }

    //用户提现设置，绑定账户
    public void toBindAccount(String payno, String realname, String txtype, String uniquekey, String smscode) {
        Map<String, String> map = new HashMap<>();
        map.put("payno", payno);
        map.put("realname", realname);
        map.put("txtype", txtype);
        map.put("uniquekey", uniquekey);
        map.put("smscode", smscode);
        HttpUtils.postRequest(BaseUrl.SETUP_USER_TX, this, map, new JsonCallback<BaseResultBean<EmptyBean>>() {
            @Override
            public BaseResultBean<EmptyBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<EmptyBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.bindAccountSuccess(response.body().msg_cn);
                } else if (response.body().code == -1) {

                } else {
                    view.bindAccountFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<EmptyBean>> response) {
                super.onError(response);
            }
        });
    }

}
